﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DongDong.Common;
using System.Data;

public partial class Admin_KCKBXX_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDrop();
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateKCKBXX();
    }

    // 删除
    protected void lvDate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int KeyID = DongDong.Common.Misc.ConvertToInt(lvDate.DataKeys[e.ItemIndex].Value);
        KCKBXX.BadDelete(KeyID);
        lvDate.EditIndex = -1;
        PopulateKCKBXX();
    }

    // 查询
    public void PopulateKCKBXX()
    {
        lvDate.DataSource = KCKBXX.GetAllByCondition(Misc.ConvertToInt(drpSheng.SelectedValue), Misc.ConvertToInt(drpShi.SelectedValue), Misc.ConvertToInt(drpQu.SelectedValue),Misc.ConvertToInt(drpType.SelectedValue),Misc.ConvertToInt(drpKKRQ.SelectedValue),Misc.ConvertToInt(drpSKRQ.SelectedValue), Misc.ConvertToInt(drpSKFS.SelectedValue),txtKeHao.Text,txtAddTimeFrom.Text,txtAddTimeTo.Text,txtEndTimeFrom.Text,txtEndTimeTo.Text,txtKCZFY.Text);
        lvDate.DataBind();
    }

    // 绑定下拉框
    public void PopulateDrop()
    {
        drpType.PopulateFromEnum<KCKBXX.typeKCKBXX>();
        drpType.Items.Insert(0, new ListItem("全部", "999"));
        drpKKRQ.PopulateFromEnum<KCKBXX.dateKKRQ>();
        drpKKRQ.Items.Insert(0, new ListItem("其他", "9999"));
        drpKKRQ.Items.Insert(0, new ListItem("全部", "999"));
        drpSKRQ.PopulateFromEnum<KCKBXX.dateSKRQ>();
        drpSKRQ.Items.Insert(0, new ListItem("其他", "9999"));
        drpSKRQ.Items.Insert(0, new ListItem("全部", "999"));
        drpSKFS.PopulateFromEnum<KCKBXX.kindSK>();
        drpSKFS.Items.Insert(0, new ListItem("全部", "999"));

        drpSheng.DataSource = S_Province.GetAll();
        drpSheng.DataValueField = "ProvinceID";
        drpSheng.DataTextField = "ProvinceName";
        drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpShi.Items.Insert(0, new ListItem("请选择", "0"));

        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        drpShi.DataSource = S_City.GetAllByCondition(ParentID, "");
        drpShi.DataValueField = "CityID";
        drpShi.DataTextField = "CityName";
        drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        drpQu.DataSource = S_District.GetAllByCondition(ParentID, "");
        drpQu.DataValueField = "DistrictID";
        drpQu.DataTextField = "DistrictName";
        drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    // 获得省市区名称
    public string GetShengShiName(object sheng, object shi)
    {
        string Return = "暂无资料";
        Return = S_District.GetPName_CNameByPID_CID(sheng, shi);
        return Return;
    }

    // 获得区名称
    public string GetQuName(string qu)
    {
        string Return = "暂无资料";
        Return = S_District.GetQuName(qu).ToString();
        return Return;
    }

    // 开课日期
    public string GetKKRQName(string kkrq)
    {
        string Return = "暂无资料";
        if ("1".Equals(kkrq) || "2".Equals(kkrq) || "3".Equals(kkrq) || "4".Equals(kkrq))
        {
            Return = Enum.GetName(typeof(KCKBXX.dateKKRQ), Misc.ConvertToInt(kkrq));
        }
        else
        {
            Return = kkrq;
        }
        return Return;
    }

    // 上课日期
    public string GetSKRQName(string skrq)
    {
        string Return = "暂无资料";
        if ("1".Equals(skrq) || "2".Equals(skrq) || "3".Equals(skrq) || "4".Equals(skrq))
        {
            Return = Enum.GetName(typeof(KCKBXX.dateSKRQ), Misc.ConvertToInt(skrq));
        }
        else
        {
            Return = skrq;
        }
        return Return;
    }

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateKCKBXX();
    }
}